﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Cosmetic.Logic;
using System.Web.UI.HtmlControls;

namespace WebApp.Controls
{
	public partial class RecommendProduct : System.Web.UI.UserControl
	{
		private ProductManager m_ProductManager		= new ProductManager();

		private int m_ShowCount = 10;
		public int ShowCount
		{
			get { return m_ShowCount; }
			set { m_ShowCount = value; }
		}


        private string m_imageSrc = "../imagesWeb/Rec01.gif";
        public string ImageSrc
        {
            get { return m_imageSrc; }
            set { m_imageSrc = value; }
        }

		private bool m_IsRecommend;

		public bool IsRecommend
		{
			get { return m_IsRecommend; }
			set 
			{ 
				m_IsRecommend = value;
				this.BindProduct();
			}
		}



		protected void Page_Load(object sender, EventArgs e)
		{
			this.BindProduct();
		}

		private void BindProduct()
		{
            try
            {
                this.lvProduct.DataSource = this.m_ProductManager.GetRecommandProductInfo().Take(m_ShowCount);
                this.lvProduct.DataBind();
            }
            catch
            {
                
            }
		}

        protected void lvProduct_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            int i ;
            HtmlImage img = e.Item.FindControl("img") as HtmlImage;

            if (img != null)
            {
                i = Convert.ToInt16(e.Item.ClientID.Substring(e.Item.ClientID.Length - 7,1))*5 + Convert.ToInt16(e.Item.ClientID.Substring(e.Item.ClientID.Length - 2)) + 1;
                if (i < 10)
                {
                    img.Src = "../imagesWeb/Rec0" + i.ToString() + ".gif"; 
                }
                else
                {
                    img.Src = "../imagesWeb/Rec" + i.ToString() + ".gif"; 
                }
            }
        }
	}
}